<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<div id="btn">click</div>
<script>
    // 管理单例的代码，
    var getSingle = function (fn) {
        var result
        return function () {
            console.log('this:', this)
            return result || (result = fn.apply(this, arguments))
        }
    }

    var bindEvent = getSingle(function () {
        var div = document.getElementById('btn')
        div.addEventListener('click', () => {
            alert('click')
        })
    })

    var render = function () {
        console.log('开始渲染')
        bindEvent()
    }

    render() // 执行绑定
    render() // 不重复绑定
    render() // 不重复绑定
</script>
</body>
</html>